// 设计应用侧边栏页面

// 关闭VSCode非必要报错
// ignore_for_file: camel_case_types, avoid_unnecessary_containers, must_be_immutable, non_constant_identifier_names

import 'package:easy_sidemenu/easy_sidemenu.dart';
import 'package:flutter/material.dart';
import 'package:project_award_statistics/pages/desktop_adwaita/about_page/about_page.dart';
import 'package:project_award_statistics/pages/desktop_adwaita/home_page/home_page.dart';
import 'package:project_award_statistics/pages/desktop_adwaita/login_page/login_page.dart';
import 'package:project_award_statistics/pages/desktop_adwaita/profile_edit/profile_edit_page.dart';

class MySideMenu_Desktop extends StatefulWidget {
  String stu_name;    // 获取当前用户(学生)姓名
  PageController pageController;  // 传入当前页面控制器方便直接切换页面
  SideMenuController sideMenu;

  // 设置构造函数所通入必需的变量
  MySideMenu_Desktop({
    super.key,
    required this.stu_name,
    required this.pageController,
    required this.sideMenu,
  });

  @override
  State<MySideMenu_Desktop> createState() => _MySideMenu_DesktopState();
}

class _MySideMenu_DesktopState extends State<MySideMenu_Desktop> {

  // 初始化父类Widget中的控件名称以便等下传入
  late PageController pageController;
  late SideMenuController sideMenu;
  late String stu_name;

  // 覆写父类构造函数
  @override
  void initState ()
    {
      pageController=widget.pageController;
      sideMenu=widget.sideMenu;
      stu_name=widget.stu_name;

      // 覆写页面更新(也就是changePage触发)时行为
      sideMenu.addListener((index){
        pageController.jumpToPage(index);
      });
      super.initState();
    }

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          SideMenu(
              controller: widget.sideMenu,
              style: SideMenuStyle(   // 设置外观 
                displayMode: SideMenuDisplayMode.compact,
                showHamburger: false,
                hoverColor: Colors.black12,   // 鼠标指针悬停颜色
                selectedColor: Colors.black12,   // 选中的颜色
                iconSize: 30,
                itemOuterPadding: EdgeInsets.only(top:15.0,bottom: 15.0),
              ),
              title: Column(
                children: [
                  Image.asset(
                    "lib/images/northwest_minzu_university_icon.png",
                    width: 100,
                    height: 100,
                  ),
                ],
              ),
              items: [
                SideMenuItem(
                  title: '个人主页',
                  iconWidget: Center(
                    child: SizedBox(
                      width: 36,
                      child: Icon(Icons.home,size: 30,)
                      ),
                  ),
                  onTap: (index,_){
                    sideMenu.changePage(index);
                  },
                ),
                SideMenuItem(
                  title: '获奖信息编辑',
                  iconWidget: Center(
                    child: SizedBox(
                      width: 36,
                      child: Icon(Icons.person,size: 30,)
                      ),
                  ),
                  onTap: (index,_){
                    sideMenu.changePage(index);
                  },
                ),
                SideMenuItem(
                  title: '关于本软件',
                  onTap: (index,_){
                    sideMenu.changePage(index);
                  },
                  iconWidget: Center(
                    child: SizedBox(
                      width: 36,
                      child: Icon(Icons.info,size: 30,)
                      ),
                  ),
                ),
                // 设置"退出登录"按钮
                SideMenuItem(
                  title: '退出登录',
                  iconWidget: Center(
                    child: SizedBox(
                      width: 36,
                      child: Icon(Icons.exit_to_app_outlined,size: 30,)
                      ),
                  ),
                  onTap: (index,_){
                    Navigator.pushReplacement(    // 按下后返回登录界面
                      context,
                      MaterialPageRoute(
                        builder: (context)=>PopScope(
                          canPop: false,
                          child: LoginPage_Desktop(),
                        ),
                      ),
                    );
                  },
                ),
              ],
            ),
            const VerticalDivider(
                width: 50,
              ),
            Expanded(
              child: PageView(
                controller: pageController,
                children: [
                  HomePage_Desktop(stu_name: stu_name),
                  ProfileEditPage_Desktop(stu_name: stu_name),
                  AboutPage_Desktop(),
                ],
              ),
            ),
        ],
      ),
    );
  }
}